/*
 * @(#) Countdown2.java 2013-8-8 下午7:08:55
 *
 * Copyright 2013 Rockwell Automation, Inc. All rights reserved.
 * Rockwell Automation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package com.osi.mes.pm;

import com.datasweep.compatibility.ui.FlatLabel;

/**
 * 倒计时
 * @author Nemo, 2013-8-8 下午7:20:12
 */
public class Countdown extends Thread
{
	long totalTime;
	long endTime;
	FlatLabel flatLabel;

	public Countdown(long time, FlatLabel flatLabel)
	{
		this.totalTime = time;
		this.endTime = time;
		this.flatLabel = flatLabel;
		this.start();
	}

	@Override
	public void run()
	{
		while (endTime >= 0)
		{
			Long time = endTime;
//			long N = time / 3600;
//			time = time % 3600;
			long K = time / 60;
			time = time % 60;
			long M = time;
			flatLabel.setText(K + ":" + M);
			endTime--;
			try
			{
				Thread.sleep(1000);
			}
			catch (InterruptedException e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public void reset()
	{
		endTime = totalTime;
	}
}
